<?php

namespace App\Providers;


use App\Repositories\AddressRepository;
use App\Repositories\CartRepository;
use App\Repositories\CouponRepository;
use App\Repositories\DayuSmsRepository;
use App\Repositories\DistributeRepository;
use App\Repositories\ExpressRepository;
use App\Repositories\GoodsRepository;
use App\Repositories\OrderRespository;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use Monolog\Logger;
use Yansongda\Pay\Pay;


class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191);
        Carbon::setLocale('zh');
        //验证手机扩展75
       // Auth::loginUsingId(75);
        \Validator::extend('mobile', function ($attribute, $value, $parameters, $validator) {
            return preg_match('/^13\d{9}$|^14\d{9}$|^15\d{9}$|^19\d{9}$|^17\d{9}$|^18\d{9}$/', $value);
        });
        //
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {

        //绑定接口和实现
        $this->app->bind('App\Interfaces\UserInterface', 'App\Repositories\UserRepository');
        //绑定分销接口
        $this->app->bind('App\Interfaces\DistributeInterface', DistributeRepository::class);
        //短信接口
        $this->app->bind('App\Interfaces\SmsService', DayuSmsRepository::class);
        //购物车接口
        $this->app->bind('App\Interfaces\CartService', CartRepository::class);
        //商品接口
        $this->app->bind('App\Interfaces\GoodsService', GoodsRepository::class);
        //我的地址接口
        $this->app->bind('App\Interfaces\AddressService', AddressRepository::class);
        //订单接口
        $this->app->bind('App\Interfaces\OrderService', OrderRespository::class);
        //物流接口
        $this->app->bind('App\Interfaces\Express', ExpressRepository::class);
        //优惠券接口
        $this->app->bind('App\Interfaces\CouponService', CouponRepository::class);
        // 往服务容器中注入一个名为 alipay 的单例对象
        $this->app->singleton('alipay', function () {
            $config = config('pay.alipay');
            // 判断当前项目运行环境是否为线上环境
            if (app()->environment() !== 'production') {
                $config['mode'] = 'dev';
                $config['log']['level'] = Logger::DEBUG;
            } else {
                $config['log']['level'] = Logger::WARNING;
            }
            // 调用 Yansongda\Pay 来创建一个支付宝支付对象
            return Pay::alipay($config);
        });
        /*  $this->app->singleton('wechat_pay', function () {
              $config = config('pay.wechat');
              if (app()->environment() !== 'production') {
                  $config['log']['level'] = Logger::DEBUG;
              } else {
                  $config['log']['level'] = Logger::WARNING;
              }
              // 调用 Yansongda\Pay 来创建一个微信支付对象
              return Pay::wechat($config);
          });*/
    }
}
